package org.example.day;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/08/02 15:30
 */
public class Solution3128 {

    public static void main(String[] args) {
        System.out.println(new Solution3128().numberOfRightTriangles(new int[][]{{0,1,0},{0,1,1},{0,1,0},{0,1,0}}));
    }

    public long numberOfRightTriangles(int[][] grid) {

        int[] lineX = new int[grid.length];
        int[] lineY = new int[grid[0].length];

        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                if(grid[i][j] == 1){
                    lineX[i]+=1;
                    lineY[j]+=1;
                }
            }
        }
        long sum = 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                if(grid[i][j] == 1){
                    if(lineX[i] > 1 && lineY[j] > 1){
                        sum+= ((long) (lineX[i] - 1) * (lineY[j] - 1));
                    }
                }
            }
        }
        return sum;
    }

}
